package com.ckh.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ckh.springboot.entity.HomeWorkStudent;
import com.ckh.springboot.entity.HomeWorkTeacher;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface HomeWorkStudentMapper extends BaseMapper<HomeWorkStudent> {
    @Select("select *  from sys_user as user , sys_homework_student\n" +
            "            as stu where identity = 0\n" +
            "            and stu.student_id =user.student_id")
    List <HomeWorkStudent> getHomeWorkTeacherList(Integer id);

    /**
     * 逻辑删除
     * @param id
     * @param studentId
     * @return
     */
    @Update("update   sys_homework_student  set submitcount = 0 ,score = 0 where homeworkid = #{id} and student_id=#{studentId}")
    int deleteHomeWorkTeacherList(Integer id ,Integer studentId);

    @Update("update sys_homework_student set score = #{score} where homeworkid = #{id} and student_id = #{studentId}")
    int updateHomeWorkTeacherList(Integer id , String score , Integer studentId);
    @Update("update  sys_homework_student set text = #{text} ,image = #{image} ,submitcount = 1  , name =  #{name}" +
            "" +
            " ,submittime = #{date} where homeworkid = #{id} and  student_id = #{studentId}")
    int uploadHomeWork(Integer id, String text, String image , String name , Integer studentId , Date date);

    /**
     * 获取up总人数
     * @return
     */
    @Select("SELECT homeworkid, COUNT(submitcount) from sys_homework_student WHERE submitcount = 1\n" +
            "group by homeworkid")
    Integer getUpCount() ;

    @Select("select * from sys_homework_student where student_id = #{id} and homeworkid  = #{homeId}")
    List<HomeWorkStudent> getStudentHomeWorkDetail(Integer id, Integer homeId);
    @Update("update sys_homework_student set score =  #{score} where  student_id = #{id} and homeworkid  = #{homeId}")
    int addScore(Integer id, Integer homeId, String score);

    @Select("select * from sys_homework_student where homeworkid = #{homeId}")
    List<HomeWorkStudent> getDoneHomeWorkStudent(Integer homeId);

}
